package com.hebeu.device.controller;

import com.github.pagehelper.PageInfo;
import com.hebeu.device.pojo.DClient;
import com.hebeu.device.service.DClientService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 王煜
 * @date 2019-6-17
 */

@RestController
@RequestMapping("/dclient")
public class DClientController {

    @Resource
    DClientService dClientService;

    /**
     * 查分页
     * @param dClient
     * @return
     */
    @RequestMapping("/list")
    public PageInfo<DClient> getDClient(DClient dClient){
        System.out.println("参数信息："+dClient.toString());
        List<DClient> dClients = dClientService.getDClients(dClient);
        PageInfo<DClient> pageInfo = new PageInfo<>(dClients);
        return pageInfo;
    }

    /**
     * 添加
     * @param dClient
     * @return
     */
    @RequestMapping("/add")
    public int add(DClient dClient){
        return dClientService.add(dClient);
    }

    /**
     * 删除
     * @param dClient
     * @return
     */
    @RequestMapping("/del")
    public int del(DClient dClient){
        return dClientService.del(dClient);
    }

    /**
     * 更新
     * @param dClient
     * @return
     */
    @RequestMapping("/update")
    public int update(DClient dClient){
        return dClientService.update(dClient);
    }

    /**
     * 查一条
     * @param cId
     * @return
     */
    @RequestMapping("/getOne")
    public DClient getOne(Integer cId){
        return dClientService.getDClientById(cId);
    }

    /**
     * 查所有
     * @param dClient
     * @return
     */
    @GetMapping("/getAll")
    public List<DClient> getAll(DClient dClient){
        List<DClient> dClients = dClientService.getAll(dClient);
        System.out.println("输出所有的客户数据");
        for (int i = 0 ; i < dClients.size() ; i++)
        System.out.println(dClients.get(i));
        return  dClients;
    }
}
